{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most examples work across multiple plotting backends, this example is also available for:\n",
    "\n",
    "* [Bokeh - mandelbrot section](../bokeh/mandelbrot_section.ipynb)\n",
    "\n",
    "HoloViews demo that used to be showcased on the [holoviews.org"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import holoviews as hv\n",
    "from holoviews import dim, opts\n",
    "hv.extension('matplotlib')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import io\n",
    "try:    from urllib2 import urlopen\n",
    "except: from urllib.request import urlopen\n",
    "\n",
    "raw = urlopen('http://assets.holoviews.org/data/mandelbrot.npy').read()\n",
    "array = np.load(io.BytesIO(raw)).astype(np.float32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dots = np.linspace(-0.45, 0.45, 19)\n",
    "fractal = hv.Image(array)\n",
    "\n",
    "# First example on the old holoviews.org homepage was:\n",
    "# ((fractal * hv.HLine(y=0)).hist() + fractal.sample(y=0))\n",
    "layouts = {y: (fractal * hv.Points(fractal.sample([(i,y) for i in dots])) +\n",
    "               fractal.sample(y=y) +\n",
    "               hv.operation.threshold(fractal, level=np.percentile(fractal.sample(y=y)['z'], 90)) +\n",
    "               hv.operation.contours(fractal, levels=[np.percentile(fractal.sample(y=y)['z'], 60)]))\n",
    "            for y in np.linspace(-0.3, 0.3, 21)}\n",
    "\n",
    "layout = hv.HoloMap(layouts, kdims='Y').collate().cols(2)\n",
    "\n",
    "layout.opts(\n",
    "    opts.Contours(color='w', show_legend=False),\n",
    "    opts.Points(s=dim('z')*50))"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
